<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  <div id="app"></div>
  <script>
    setTimeout(() => {
      console.log('test');
    }, 0);
    // 类似 vue 的nextTick 等待dom更新完之后，再取dom中的数据
    let mutationObserver = new MutationObserver(() => {
      console.log(app.children.length); // 异步的,比定时器快
    });
    mutationObserver.observe(app, {childList: true}); // 监听的节点，和子节点
    for (let i = 0; i < 10; i++) {
      app.appendChild(document.createElement('p'));
    }
    for (let i = 0; i < 10; i++) {
      app.appendChild(document.createElement('p'));
    }
    for (let i = 0; i < 10; i++) {
      app.appendChild(document.createElement('p'));
    }
  </script>
</body>
</html>